/*--------------------------------------------------------------------------
Modified from GNU Group's SDCC
Only for study purpose
---------------------------------------------------------------------------*/
#ifndef __COMPILER_GROUP_GLOBL_H
#define __COMPILER_GROUP_GLOBL_H

#include <memory.h>
#include <stdlib.h>
#include <stdio.h>
#include "set.h"

#ifndef bool
    #define bool char
	#define BOOL char
    #define false ((bool)0)
    #define true  ((bool)1)
    #define FALSE ((bool)0)
    #define TRUE  ((bool)1)
#endif

#ifndef max
#  define max(a,b) (a > b ? a : b)
#endif

#ifndef min
#  define min(a,b) (a < b ? a : b)
#endif

//@nvcuong : LABEL TYPE
#ifndef ___LABEL__TYPE___
	#define ___LABEL__TYPE___
	#define L_BODY		"BDY"	/* Top of the body of a for loop.	      */
	#define L_COND_END	"QE"	/* End of conditional.			      */
	#define L_COND_FALSE	"QF"	/* True part of conditional (?:).	      */
	#define L_DOEXIT	"DXIT"	/* Just after the end of the do/while.	      */
	#define L_DOTEST	"DTST"	/* Just above the test in a do/while.	      */
	#define L_DOTOP		"DTOP"	/* Top of do/while loop.		      */
	#define L_ELSE		"EL"	/* Used by else processing.		      */
	#define L_END		"E"	/* End of relational/logical op.	      */
	#define L_FALSE		"F"	/* False target of relational/logical op.     */
	#define L_INCREMENT	"INC"	/* Just above the increment part of for loop. */
	#define L_LINK		"L"	/* Offset passed to link instruction.	      */
	#define L_NEXT		"EXIT"	/* Outside of loop, end of if clause.	      */
	#define L_RET		"RET"   /* Above clean-up code at end of subroutine.  */
	#define L_STRING	"S"	/* Strings.				      */
	#define L_SWITCH	"SW"	/* Used for switches.			      */
	#define L_TEST		"TST"	/* Above test in while/for/if.		      */
	#define L_TRUE		"T"	/* True target of relational/logical operator.*/
	#define L_VAR		"V"	/* Local-static variables.		      */
#endif


#define CHARSIZE    1
#define SHORTSIZE   2
#define INTSIZE     2
#define LONGSIZE    4
#define PTRSIZE     2
#define MAX_LENGTH_BUFFER 2048

extern int currBlockno;			/* currBlockno is in parser.c */
extern int NestLevel;          
extern int stackPtr;           

#define MAX_DCL_STACK	512

/* VC Error Style */
#define YY_VC_ERROR_STYLE	0	/* 0: my style, 1: VC Style */

#define USE_STDOUT_FOR_ERRORS   0
#if USE_STDOUT_FOR_ERRORS
#define DEFAULT_ERROR_OUT       stdout
#else
#define DEFAULT_ERROR_OUT       stderr
#endif

/* extern from yylex.c */
extern int lexLineno;			/* lexLineno is in yylex.c */
extern char* lexFilename;		/* lexFilename is in yylex.c */
extern int column;
extern int fatalError;
extern int yyerror(char *s);

void ccerror(char *newFilename, int newLineno, const char *format, ...);
void yylexerror(const char *format, ...);
void yylexwarning(const char *format, ...);
void yylexsumary();

#endif